import 'package:concierge/app/common/AppLifecycleObserver.dart';
import 'package:concierge/app/common/app_theme.dart';
import 'package:concierge/app/common/common.dart';
import 'package:concierge/app/req/provider/CenterApiProvider.dart';
import 'package:concierge/app/req/provider/LifeApiProvider.dart';
import 'package:concierge/app/req/provider/PlateApiProvider.dart';
import 'package:concierge/app/routes/app_routes.dart';
import 'package:concierge/app/service/GlobalService.dart';
import 'package:concierge/app/service/LogOssService.dart';
import 'package:concierge/app/service/OssService.dart';
import 'package:concierge/generated/locales.g.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

Future<void> main() async {
  WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
  await SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  widgetsBinding.addObserver(AppLifecycleObserver());
  final routeObserver = RouteObserver<PageRoute>();
  Get.put(routeObserver);

  runApp(
    ScreenUtilInit(
      designSize: Size(375, 812),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context, child) {
        String countryCode = Get.deviceLocale?.countryCode ?? 'US';
        String languageCode = changeLanguage(Get.deviceLocale, 1);
        Locale locale = Locale(languageCode, countryCode);
        // Get.updateLocale(locale);
        return GetMaterialApp(
          title: "VERTU Life",
          initialRoute: Routes.splash,
          getPages: Routes.routes,
          navigatorObservers: [routeObserver, FlutterSmartDialog.observer],
          builder: FlutterSmartDialog.init(),
          translationsKeys: AppTranslation.translations,
          theme: AppTheme.light,
          darkTheme: AppTheme.dark,
          themeMode: themeMode.value,
          locale: locale,
          fallbackLocale: Locale('en', 'US'),
          defaultTransition: Transition.cupertino,
          debugShowCheckedModeBanner: false,
          initialBinding: BindingsBuilder(() {
            Get.put(GlobalService());
            Get.put(CenterApiProvider());
            Get.put(LifeApiProvider());
            Get.put(PlateApiProvider());
            Get.put(LogOssService());
            Get.put(OssService());
          }),
        );
      },
    ),
  );
}
